import SelectUtil from '@/SelectUtil';
import MovementCommon from 'code/Core/Common/MovementCommon';
import SelectCommon from 'code/Core/Common/SelectCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 死亡缠绕
 */
export default class DK_DeathCoil extends AbilityBase {
    static instance: DK_DeathCoil;
    onMissileReach(p: TargetMissileConfig) {
        let lv = this.getAbilityLevel(p.caster);
        let dmg = 30 + UnitCommon.取法强(p.caster) * (0.4 + 0.4 * lv);
        if (IsUnitEnemy(p.target, GetOwningPlayer(p.caster))) {
            DamageSystemInstance.applyPoisionDamage(p.target, p.caster, dmg, this.id);
        } else {
            DamageSystemInstance.applyHeal(p.target, p.caster, dmg, this.id);
        }
        DestroyEffect(AddSpecialEffectTarget('Abilities\\Spells\\Undead\\DeathCoil\\DeathCoilSpecialArt.mdl', p.target, 'origin'));
    }
    constructor(id: string) {
        super(id);
        DK_DeathCoil.instance = this;
        se.onUnitSpellEffect(this.spellEffect.bind(this), this.id);
    }
    spellEffect() {
        this.cast(GetUnitX(GetSpellTargetUnit()), GetUnitY(GetSpellTargetUnit()), GetTriggerUnit(), GetSpellTargetUnit());
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        let us = [].concat(SelectUtil.getEnemyUnitsInRange(target, 275), SelectCommon.getAllyUnitInRange(target, 275));
        for (let u of us) {
            MovementCommon.TargetMissile({
                target: u,
                caster: source,
                missile: 'Abilities\\Spells\\Undead\\DeathCoil\\DeathCoilMissile.mdl',
                speed: 500,
                onReach: this.onMissileReach.bind(this),
            });
        }
    }
}
